#include "Common.hpp"
#include "Socket.hpp"
#include "Protocol.hpp"
#include "Log.hpp"
using namespace SocketModule;
using namespace LogModule;
void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " server_ip server_port" << std::endl;
}

void GetDataFromStdin(int *x, int *y, char *oper)
{
    std::cout << "Please Enter x: ";
    std::cin >> *x;
    std::cout << "Please Enter y: ";
    std::cin >> *y;
    std::cout << "Please Enter oper: ";
    std::cin >> *oper;
}

int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    std::string server_ip = argv[1];
    uint16_t server_port = std::stoi(argv[2]);

    // 创建客户端套接字(客户端无需绑定 监听套接字)
    std::shared_ptr<Socket> client = std::make_shared<TcpSocket>();
    client->BuildTcpClientMethod();

    // 客户端连接
    if (client->Connect(server_ip, server_port) < 0)
    {
        // 失败
        std::cerr << "connect error" << std::endl;
        exit(CONNECT_ERR);
    }

    std::unique_ptr<Protocol> protocol = std::make_unique<Protocol>();
    std::string resp_buffer;

    // 启动客户端
    while (true)
    {
        // 接收用户数据
        int x, y;
        char oper;
        GetDataFromStdin(&x, &y, &oper);
        // 客户端构建序列化请求
        std::string client_request;
        protocol->BulidingRequest(client_request);
        // 客户端接收响应(完整性检查)

        // 反序列化响应

        // 显示结果
    }

    // 循环结束 客户端关闭释放资源
}